package org.example.sportdemo.service;

import org.example.sportdemo.entity.GroundOrder;
import org.example.sportdemo.mapper.GroundOrderMapper;
import org.example.sportdemo.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class GroundOrderService {

    @Autowired
    private GroundOrderMapper groundOrderMapper;

    public List<GroundOrder> selectAll(){
        return groundOrderMapper.selectAll();
    }

    public PageUtils queryPage(Map<String, Object> params) {
        //总数据
        List<GroundOrder> groundList = groundOrderMapper.selectAll();
        //总条数
        Integer totalCount = groundOrderMapper.selectCount();
        //当前页
        Integer currPage = Integer.valueOf((String) params.get("currPage"));
        //每页条数
        Integer pageSize = Integer.valueOf((String) params.get("pageSize"));
        return new PageUtils(totalCount,(Integer) pageSize,currPage,groundList);
    }

    public void addGroundOrder(GroundOrder groundOrder) {

        Date date = new Date();
        groundOrder.setCreate_time(date);
        groundOrderMapper.addGroundOrder(groundOrder);

    }

    public GroundOrder selectById(Integer id) {
        return groundOrderMapper.selectById(id);
    }

    public void updateGroundOrder(GroundOrder groundOrder) {
        groundOrderMapper.updateGroundOrder(groundOrder);
    }

    public void deleteByIds(Integer[] ids) {
        groundOrderMapper.deleteByIds(ids);
    }
}
